﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IHISCETeim.DAL;
using IHISCETeim.Model;
using IHISCETeim.Library;
using System.Data;
using IHISCETeim.Web;
using System.Configuration;

namespace IHISCETeim.BLL
{
    /// <summary>
    /// 经销商平台,用于发送邮件相关方法
    /// </summary>
    public  class AgentEmailController
    {

        #region 2014-10-12 改成获取对象,用于统一数据库处理
        /// <summary>
        /// 代理商提交品情后,通知服务担当
        /// </summary>
        /// <param name="QltyId"></param>
        /// <param name="IsEditByAgent">是否重新编辑提交</param>
        public static SEMailListInfo GetAddQltyEmail(AgentQltyInfo obj, bool IsEditByAgent)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.SrvActUserId);
            objEmail.MailTo = svrObj.EMail;
            objEmail.Subject = IsEditByAgent ? string.Format("驳回的品情{0}经销商{1}已重新提交,需要重新处理", obj.ClaimsNumber, obj.AgentName) : string.Format("您有来自经销商{1}的新品情需要处理,品情号{0}", obj.ClaimsNumber, obj.AgentName);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("故障描述:<br/><b>{0}</b><br/>", obj.FaultDescription);
            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入经销商终端平台进行处理.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";

            return objEmail;
        }
        public static SEMailListInfo GetAddQltyEmail(AgentQltyInfo obj)
        {
            return GetAddQltyEmail(obj, false);
        }

        /// <summary>
        /// 服务经理/部长 确认邮件
        /// </summary>
        /// <param name="QltyId"></param>
        public static SEMailListInfo GetSvrMgrEmail(AgentQltyInfo obj, List<AgentQltyPartsInfo> listParts)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            //AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.SrvMangerUserId);
           // List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(obj.QltyId);

            objEmail.MailTo = svrObj.EMail;
            objEmail.Subject = string.Format("您有来自经销商{1}的品情需要审核,品情号{0}", obj.ClaimsNumber, obj.AgentName);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("服务担当:<b>{0}</b><br/>", obj.SrvActRealName);
            objEmail.Body += string.Format("需求配件总金额:<br/><b>{0} RMB</b><br/>", listParts.Sum(e => e.LastPurPrice));

            objEmail.Body += string.Format("故障描述:<br/><b>{0}</b><br/>", obj.FaultDescription);

            //mailContent += string.Format("需求配件明细:<br/><b>{0}</b><br/>", obj.FaultDescription);
            //List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId);
            //foreach (AgentQltyPartsInfo itm in listParts)
            //{
            //    mailContent += "<table>";
            //    mailContent += "<tr><td>配件号<td><td>配件名称<td><td>数量<td><td></td>";

            //    mailContent += "</table>";
            //}

            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入经销商终端平台进行处理.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            return objEmail;

        }

        /// <summary>
        /// 品情已确认,发邮件通知配件部
        /// </summary>
        /// <param name="QltyId"></param>
        public static SEMailListInfo GetSendPartsEmail(AgentQltyInfo obj, List<AgentQltyPartsInfo> listParts)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            //return;
            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            // List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId).FindAll(e => e.PartsDemand == "索赔发货");

            objEmail.MailTo = AgentConfigController.PartsManagerEmails; ;
            objEmail.Subject = string.Format("您有来自经销商{1}的品情需要配件,品情号{0}", obj.ClaimsNumber, obj.AgentName);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("需求配件总金额:<br/><b>{0} RMB</b><br/>", listParts.Sum(e => e.LastPurPrice));
            objEmail.Body += string.Format("配件发送日期:<b>{0}</b><br/>", obj.PartsSendDate);
            objEmail.Body += string.Format("配件发送方式:<b>{0}</b><br/>", obj.PartsSendType);
            objEmail.Body += string.Format("收件人:<b>{0}</b>&nbsp;&nbsp;联系方式:<b>{1}</b><br/>", obj.PartsAcceptName, obj.PartsAcceptTel);
            objEmail.Body += string.Format("配件接收地址:<b>{0}</b><br/>", obj.PartsAcceptAddress);

            objEmail.Body += string.Format("配件明细如下:<br/>{0}", "");
            objEmail.Body += "<table border='1'>";
            objEmail.Body += string.Format("<caption>{0}</caption>", obj.AgentName);
            objEmail.Body += "<tr><td width='100px'>机号</td><td width='100px'>索赔号</td><td width='100px'>配件号</td><td width='120px'>配件名称</td><td width='100px'>需求数量</td><td width='100px'>库位</td><td width='100px'>厦门库 库存</td><td>配件需求类型</td><td>发货单号</td><td>备注</td></tr>";
            foreach (AgentQltyPartsInfo itm in listParts)
            {
                DataTable onHandDT = SBOController.GetOITMSWWOnHand(itm.ItemCode, "W02001");
                
                string sww    = onHandDT.Rows.Count<=0?"": onHandDT.Rows[0]["sww"].ToString();
                string OnHand = onHandDT.Rows.Count<=0?"":onHandDT.Rows[0]["OnHand"].ToString();
                objEmail.Body += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td><td>{9}</td></tr>",obj.SerialNumber,obj.ClaimsNumber,itm.ItemCode,itm.Dscription,itm.Quantity,sww,OnHand,itm.PartsDemand,"",itm.Remark);
                //objEmail.Body += string.Format("<tr><td>{6}</td><td>{7}</td><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{8}</td></tr>", itm.ItemCode, itm.Dscription, itm.Quantity, sww, OnHand, itm.PartsDemand, obj.SerialNumber, obj.ClaimsNumber, itm.Remark);
            }
            objEmail.Body += "</table>";

            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>注意:<br/>1.当配件实际出厂后,你需要登陆 经销商终端平台 填写相应的配件出厂时间.<br/>2.配件在ERP上做发货单后,信息平台会自动将相应的ERP做单时间读取过来,所以请你及时做单.";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            //SEMailListController.Add(PartsEmail, mailSubject, mailContent);
            return objEmail;
        }

        /// <summary>
        /// 品情已确认,发邮件通知服务部内群通知供应商
        /// </summary>
        /// <param name="QltyId"></param>
        public static SEMailListInfo GetSendPartsToIHISCESvrSupperEmail(AgentQltyInfo obj, List<AgentQltyPartsInfo> listParts)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);         
            //  List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId).FindAll(e => e.PartsDemand == "供应商发货");

            objEmail.MailTo = AgentConfigController.IHISCESvrSupperEmails;
            objEmail.Subject = string.Format("您有来自经销商{1}的品情需要 供应商提供配件,品情号{0}", obj.ClaimsNumber, obj.AgentName);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("需求配件总金额:<br/><b>{0} RMB</b><br/>", listParts.Sum(e => e.LastPurPrice));
            objEmail.Body += string.Format("配件发送日期:<b>{0}</b><br/>", obj.PartsSendDate);
            objEmail.Body += string.Format("配件发送方式:<b>{0}</b><br/>", obj.PartsSendType);
            objEmail.Body += string.Format("配件接收地址:<b>{0}</b><br/>", obj.PartsAcceptAddress);

            objEmail.Body += string.Format("配件明细如下:<br/>{0}", "");
            objEmail.Body += "<table  border='1'>";
            objEmail.Body += "<tr><td width='100px' >配件号</td><td width='120px'>配件名称</td><td width='100px'>数量</td></tr>";
            foreach (AgentQltyPartsInfo itm in listParts)
            {
                objEmail.Body += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", itm.ItemCode, itm.Dscription, itm.Quantity);
            }
            objEmail.Body += "</table>";

            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>注意:<BR/>1.请及时跟进供应商发货情况，一旦发货,请进入 经销商终端平台 维护相应的供应商发货时间<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
           // SEMailListController.Add(IHISCESvrSupperEmails, mailSubject, mailContent);
            return objEmail;
        }

        /// <summary>
        /// 品情驳回,服务担当页面
        /// </summary>
        /// <param name="QltyId"></param>
        public static SEMailListInfo GetCancelQltyEmail(AgentQltyInfo obj)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.UserId);
            //邮件接收人为，经销商及相应服务担当
            objEmail.MailTo = svrObj.EMail;
            objEmail.MailTo += ";" + OUserController.GetById(obj.SrvActUserId).EMail;
            objEmail.Subject = string.Format("您的品情{0}已被驳回", obj.ClaimsNumber);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);

            objEmail.Body += string.Format("驳回原因:<br/><b>{0}</b><br/>", obj.RejectReason);
            objEmail.Body += string.Format("<b>您可以进入信息平台对品情{0}修改再提交审核。</b><br/>", obj.ClaimsNumber);
            //mailContent += string.Format("需求配件明细:<br/><b>{0}</b><br/>", obj.FaultDescription);
            //List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId);
            //foreach (AgentQltyPartsInfo itm in listParts)
            //{
            //    mailContent += "<table>";
            //    mailContent += "<tr><td>配件号<td><td>配件名称<td><td>数量<td><td></td>";

            //    mailContent += "</table>";
            //}

            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 查看 进行查看.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            //SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);
            return objEmail;
        }

        /// <summary>
        /// 拒赔品情
        /// </summary>
        /// <param name="QltyId"></param>
        public static SEMailListInfo GetExclusionsQltyEmail(AgentQltyInfo obj)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.UserId);
            //邮件接收人为，经销商
            objEmail.MailTo = svrObj.EMail;
            //mailEmail += ";" + OUserController.GetById(obj.SrvActUserId).EMail;
            objEmail.Subject = string.Format("您的品情{0}已被拒赔", obj.ClaimsNumber);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            //mailContent += string.Format("需求配件明细:<br/><b>{0}</b><br/>", obj.FaultDescription);
            //List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId);
            //foreach (AgentQltyPartsInfo itm in listParts)
            //{
            //    mailContent += "<table>";
            //    mailContent += "<tr><td>配件号<td><td>配件名称<td><td>数量<td><td></td>";

            //    mailContent += "</table>";
            //}

            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 查看 进行查看.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            //SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);
            return objEmail;
        }

        /// <summary>
        /// 驳回品情，审核页面
        /// </summary>
        /// <param name="QltyId"></param>
        public static SEMailListInfo GetNoPassEmail(AgentQltyInfo obj,int opUserId)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.SrvActUserId);
            /*获取所有需要接收品情驳回的人员,服务担当,服务经理*/
            objEmail.MailTo = OUserController.GetById(obj.SrvActUserId).EMail;//服务担当EMAIL
            int userId = obj.SrvActUserId;
            while (true)
            {
                AgentPowerConfigInfo power = AgentConfigController.GetByUserId(userId);
                if (power.ParId == 0)
                    break;
                AgentPowerConfigInfo SvrManagerPower = AgentConfigController.GetById(power.ParId);
                userId = SvrManagerPower.UserId;
                if (obj.SrvMangerUserId == userId)
                    break;


                objEmail.MailTo = objEmail.MailTo + ";" + OUserController.GetById(SvrManagerPower.UserId).EMail;
            }
            //
            OUserInfo AgentObj = OUserController.GetById(obj.UserId);
            objEmail.MailTo = objEmail.MailTo + ";" + AgentObj.EMail;



            objEmail.Subject = string.Format("您的品情{0}已被{1}驳回", obj.ClaimsNumber, OUserController.GetById(opUserId).RealName);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("驳回原因:<br/><b>{0}</b><br/>", obj.RejectReason);
            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 查看 进行查看.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            //SEMailListController.Add(EMail, mailSubject, mailContent);
            return objEmail;
        }

        /// <summary>
        /// 确认品情后,通知经销商
        /// </summary>
        /// <param name="QltyId"></param>
        public static SEMailListInfo GetEndEmail(AgentQltyInfo obj)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.UserId);

            objEmail.MailTo = svrObj.EMail;
            objEmail.Subject = string.Format("您的品情{0}机号{1}服务担当已确认", obj.ClaimsNumber, obj.SerialNumber);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("我司 服务担当{0} 已处理完此品情,同时也通知配件部发货(如有需求)<br/>", obj.SrvActRealName);
            objEmail.Body += "可进入 <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 进入查看.<br/>";
            objEmail.Body += "==============================================================================<br/>";
            objEmail.Body += "注意:<BR/>1.如果有配件需求,在收到配件后,务必进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 进入查看 填写相应的配件收货时间(同一单品情以最后一次收到配件为准)<br/>";
            objEmail.Body += "2.如故障已排除,也务必进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 进入查看 填写相应的故障排除时间<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            //SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);
            return objEmail;


        }
        /// <summary>
        /// 2015-06-12 品情确认后，如果金额超出限制，则发邮件通知应总
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="listParts"></param>
        /// <returns></returns>
        public static SEMailListInfo GetAlarmMoneySendEmail(AgentQltyInfo obj, List<AgentQltyPartsInfo>  listParts)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.UserId);

            objEmail.MailTo = AgentConfigController.QltyAlarmEmail;
            objEmail.Subject = string.Format("通知:品情{0}机号{1}的索赔总金额超{2}元", obj.ClaimsNumber, obj.SerialNumber,AgentConfigController.QltyAlarmMoney);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("经销商:<b>{0}</b><br/>", obj.AgentName);

            //List<AgentQltyPartsInfo> listParts=AgentQltyController.GetAllPartsByQltyId(obj.q)

            objEmail.Body += string.Format("配件明细如下:<br/>{0}", "");
            objEmail.Body += "<table border='1'>";         
            objEmail.Body += "<tr><td width='100px'>配件号</td><td width='120px'>配件名称</td><td width='100px'>需求数量</td>><td>成本单价</td></tr>";
            foreach (AgentQltyPartsInfo itm in listParts)
            {

                objEmail.Body += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", itm.ItemCode, itm.Dscription, itm.Quantity, itm.LastPurPrice);
                //objEmail.Body += string.Format("<tr><td>{6}</td><td>{7}</td><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{8}</td></tr>", itm.ItemCode, itm.Dscription, itm.Quantity, sww, OnHand, itm.PartsDemand, obj.SerialNumber, obj.ClaimsNumber, itm.Remark);
            }
            objEmail.Body += "</table>";


           
            objEmail.Body += "==============================================================================<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            //SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);
            return objEmail;


        }
        /// <summary>
        /// 获取内部通报邮件
        /// </summary>
        /// <param name="QltyId"></param>
        /// <param name="mailTos"></param>
        /// <param name="SvrScheme"></param>
        /// <returns></returns>
        public static SEMailListInfo GetApproveSchemeEmail(int QltyId, string mailTos,string SvrScheme, string comeform)
        {
            //
            string exportUrl = string.Format("{0}/AgentSys/AgentQltyExeclSing.aspx?ID={1}", ConfigurationManager.AppSettings["ExportExcelWebUrl"], QltyId);
            //
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            objEmail.MailTo = mailTos;
            objEmail.Subject = string.Format("品情{0}内部通报与对策{1}", obj.ClaimsNumber, comeform);
            objEmail.Body = string.Format("品情号:<b><a href='{1}' target='_blank'>{0}</a></b><br/>", obj.ClaimsNumber, exportUrl);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("经销商:<b>{0}</b><br/>", obj.AgentName);
            objEmail.Body += string.Format("<b>内部通报与对策内容:</b><br/>{0}", SvrScheme);
            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入  信息平台 进行查看.<br/>";
            objEmail.Body += "<BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            return objEmail;
        }
        /// <summary>
        /// 获取给经理部长通知邮件,内部通报
        /// </summary>
        /// <param name="QltyId"></param>
        /// <returns></returns>
        public static SEMailListInfo GetSvrMgrSvrSchemEmail(AgentQltyInfo obj)
        { 
            SEMailListInfo objEmail = new SEMailListInfo();
            objEmail.EmailType = 1;
            //  AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            int userId = obj.SrvActUserId;
            while (true)
            {
                AgentPowerConfigInfo power = AgentConfigController.GetByUserId(userId);
                if (power.ParId == 0)
                    break;
                AgentPowerConfigInfo SvrManagerPower = AgentConfigController.GetById(power.ParId);
                userId = SvrManagerPower.UserId;
               
                objEmail.MailTo += OUserController.GetById(SvrManagerPower.UserId).EMail+";";
            }

            objEmail.Subject = string.Format("品情{0}有内部通报与对策需要您审核", obj.ClaimsNumber);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("经销商:<b>{0}</b><br/>", obj.AgentName);
            objEmail.Body += string.Format("<b>内部通报与对策内容:</b><br/>{0}", obj.SvrScheme);
            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入  信息平台 进行查看.<br/>";
            objEmail.Body += "<BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            return objEmail;
        }
        #endregion


        #region 2016-03-14 保外业务配件
        public static SEMailListInfo GetAddPWOrderEmail(AgentPartOrderInfo obj)
        {
            SEMailListInfo objEmail = new SEMailListInfo();

            // AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            //OUserInfo svrObj = OUserController.GetById(obj);

            objEmail.MailTo =AgentConfigController.PWPartPassEmails;
            objEmail.Subject =string.Format("有新的保外配件订单需要审批,订单号{0}", obj.OrderNumber);
            objEmail.Body = string.Format("经销商:<b>{0}</b><br/>", obj.AgentName);
            objEmail.Body = string.Format("订单号:<b>{0}</b><br/>", obj.OrderNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("申请说明:<br/><b>{0}</b><br/>", obj.Remark);
            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入经销商终端平台进行处理.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";

            return objEmail;
        }
        /// <summary>
        /// 通过审批后通知经销商
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static SEMailListInfo GetPassPWOrderEmail(int OrderId)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            AgentPartOrderInfo obj = AgentPartOrderController.GetList(OrderId);
            OUserInfo svrObj = OUserController.GetById(obj.AgentId);

            objEmail.MailTo = svrObj.EMail;
            objEmail.Subject = string.Format("您的保外配件订单已通过审批,订单号{0}", obj.OrderNumber);
            objEmail.Body = string.Format("订单号:<b>{0}</b><br/>", obj.OrderNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("申请说明:<br/><b>{0}</b><br/>", obj.Remark);
            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入经销商终端平台查看.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";

            return objEmail;
        }

        /// <summary>
        /// 再确认通知经销商
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static SEMailListInfo GetReCheckPWOrderEmail(int OrderId)
        {
            SEMailListInfo objEmail = new SEMailListInfo();
            AgentPartOrderInfo obj = AgentPartOrderController.GetList(OrderId);
            OUserInfo svrObj = OUserController.GetById(obj.AgentId);

            objEmail.MailTo = svrObj.EMail;
            objEmail.Subject = string.Format("您的保外配件订单需再确认,订单号{0}", obj.OrderNumber);
            objEmail.Body = string.Format("订单号:<b>{0}</b><br/>", obj.OrderNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            objEmail.Body += string.Format("再确认说明:<br/><b>{0}</b><br/>", obj.ReCheckRemark);
            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入经销商终端平台查看.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";

            return objEmail;
        }
        /// <summary>
        /// 旧件入库通知服务担当
        /// </summary>
        /// <param name="QltyId"></param>
        /// <returns></returns>
        public static SEMailListInfo GetOldPartReturn(int QltyId)
        {
            AgentQltyInfo objqlty = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo objUser = OUserController.GetById(objqlty.SrvActUserId);

            SEMailListInfo objEmail = new SEMailListInfo();
           

            objEmail.MailTo = objUser.EMail;
            objEmail.Subject = string.Format("品情号{0}的旧件已返回到工场,请确认", objqlty.ClaimsNumber);
            objEmail.Body = string.Format("品情号:<b>{0}</b><br/>", objqlty.ClaimsNumber);
            objEmail.Body += string.Format("机号:<b>{0}</b><br/>", objqlty.SerialNumber);
            objEmail.Body += string.Format("经销商:<br/><b>{0}</b><br/>", objqlty.AgentName);
           

            objEmail.Body += "<br/>==============================================================================<br/>";
            objEmail.Body += "<br/>请进入经销商终端平台->品情旧件管理 查看.<br/>";
            objEmail.Body += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";

            return objEmail;
        }
        #endregion
        /*
        /// <summary>
        /// 代理商提交品情后,通知服务担当
        /// </summary>
        /// <param name="QltyId"></param>
        /// <param name="IsEditByAgent">是否重新编辑提交</param>
        public static void AddQltyEmail(int QltyId,bool IsEditByAgent)
        {
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.SrvActUserId);

            string mailSubject =IsEditByAgent?  string.Format("驳回的品情{0}经销商{1}已重新提交,需要重新处理", obj.ClaimsNumber, obj.AgentName):string.Format("您有来自经销商{1}的新品情需要处理,品情号{0}", obj.ClaimsNumber, obj.AgentName);
            string mailContent = string.Format("品情号:<b>{0}</b><br/>",obj.ClaimsNumber);
            mailContent += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            mailContent += string.Format("故障描述:<br/><b>{0}</b><br/>", obj.FaultDescription);
            mailContent += "<br/>==============================================================================<br/>";
            mailContent += "<br/>请进入经销商终端平台进行处理.<br/>";
            mailContent += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);
        }
        public static void AddQltyEmail(int QltyId)
        {
            AddQltyEmail(QltyId, false);
        }

        /// <summary>
        /// 服务经理/部长 确认邮件
        /// </summary>
        /// <param name="QltyId"></param>
        public static void SvrMgrEmail(int QltyId)
        {
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.SrvMangerUserId);
            List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId);

            string mailSubject = string.Format("您有来自经销商{1}的品情需要审核,品情号{0}", obj.ClaimsNumber, obj.AgentName);
            string mailContent = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            mailContent += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            mailContent += string.Format("服务担当:<b>{0}</b><br/>", obj.SrvActRealName);
            mailContent += string.Format("需求配件总金额:<br/><b>{0} RMB</b><br/>", listParts.Sum(e=>e.LastPurPrice));

            mailContent += string.Format("故障描述:<br/><b>{0}</b><br/>", obj.FaultDescription);

            //mailContent += string.Format("需求配件明细:<br/><b>{0}</b><br/>", obj.FaultDescription);
            //List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId);
            //foreach (AgentQltyPartsInfo itm in listParts)
            //{
            //    mailContent += "<table>";
            //    mailContent += "<tr><td>配件号<td><td>配件名称<td><td>数量<td><td></td>";

            //    mailContent += "</table>";
            //}

            mailContent += "<br/>==============================================================================<br/>";
            mailContent += "<br/>请进入经销商终端平台进行处理.<br/>";
            mailContent += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);

        }
        /// <summary>
        /// 品情已确认,发邮件通知配件部
        /// </summary>
        /// <param name="QltyId"></param>
        public static void SendPartsEmail(int QltyId)
        {
            //return;
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
          
            string PartsEmail = AgentConfigController.PartsManagerEmails;
            List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId).FindAll(e => e.PartsDemand == "索赔发货");

            string mailSubject = string.Format("您有来自经销商{1}的品情需要配件,品情号{0}", obj.ClaimsNumber, obj.AgentName);
            string mailContent = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            mailContent += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            mailContent += string.Format("需求配件总金额:<br/><b>{0} RMB</b><br/>", listParts.Sum(e => e.LastPurPrice));
            mailContent += string.Format("配件发送日期:<b>{0}</b><br/>", obj.PartsSendDate);
            mailContent += string.Format("配件发送方式:<b>{0}</b><br/>", obj.PartsSendType);
            mailContent += string.Format("收件人:<b>{0}</b>&nbsp;&nbsp;联系方式:<b>{1}</b><br/>", obj.PartsAcceptName,obj.PartsAcceptTel);
            mailContent += string.Format("配件接收地址:<b>{0}</b><br/>", obj.PartsAcceptAddress);
           
            mailContent += string.Format("配件明细如下:<br/>{0}", "");
            mailContent += "<table border='1'>";
            mailContent += string.Format( "<caption>{0}</caption>",obj.AgentName);
            mailContent += "<tr><td width='100px'>机号</td><td width='100px'>索赔号</td><td width='100px'>配件号</td><td width='120px'>配件名称</td><td width='100px'>需求数量</td><td width='100px'>库位</td><td width='100px'>厦门库 库存</td><td>配件需求类型</td><td>发货单号</td><td>备注</td></tr>";
            foreach (AgentQltyPartsInfo itm in listParts)
            {
                DataTable onHandDT = SBOController.GetOITMSWWOnHand(itm.ItemCode,"W02001");
                string sww = onHandDT.Rows[0]["sww"].ToString();
                string OnHand = onHandDT.Rows[0]["OnHand"].ToString();
                mailContent += string.Format("<tr><td>{6}</td><td>{7}</td><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{8}</td></tr>", itm.ItemCode, itm.Dscription, itm.Quantity, sww, OnHand, itm.PartsDemand,obj.SerialNumber,obj.ClaimsNumber, itm.Remark);
            }
            mailContent += "</table>";

            mailContent += "<br/>==============================================================================<br/>";
            mailContent += "<br/>注意:<br/>1.当配件实际出厂后,你需要登陆 经销商终端平台 填写相应的配件出厂时间.<br/>2.配件在ERP上做发货单后,信息平台会自动将相应的ERP做单时间读取过来,所以请你及时做单.";
            mailContent += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            SEMailListController.Add(PartsEmail, mailSubject, mailContent);
        }
        /// <summary>
        /// 品情已确认,发邮件通知服务部内群通知供应商
        /// </summary>
        /// <param name="QltyId"></param>
        public static void SendPartsToIHISCESvrSupperEmail(int QltyId)
        {
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
          
            string IHISCESvrSupperEmails = AgentConfigController.IHISCESvrSupperEmails;
            List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId).FindAll(e => e.PartsDemand == "供应商发货");

            string mailSubject = string.Format("您有来自经销商{1}的品情需要 供应商提供配件,品情号{0}", obj.ClaimsNumber, obj.AgentName);
            string mailContent = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            mailContent += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            mailContent += string.Format("需求配件总金额:<br/><b>{0} RMB</b><br/>", listParts.Sum(e => e.LastPurPrice));
            mailContent += string.Format("配件发送日期:<b>{0}</b><br/>", obj.PartsSendDate);
            mailContent += string.Format("配件发送方式:<b>{0}</b><br/>", obj.PartsSendType);
            mailContent += string.Format("配件接收地址:<b>{0}</b><br/>", obj.PartsAcceptAddress);

            mailContent += string.Format("配件明细如下:<br/>{0}", "");
            mailContent += "<table  border='1'>";
            mailContent += "<tr><td width='100px' >配件号</td><td width='120px'>配件名称</td><td width='100px'>数量</td></tr>";
            foreach (AgentQltyPartsInfo itm in listParts)
            {
                mailContent += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", itm.ItemCode, itm.Dscription, itm.Quantity);
            }
            mailContent += "</table>";

            mailContent += "<br/>==============================================================================<br/>";
            mailContent += "<br/>注意:<BR/>1.请及时跟进供应商发货情况，一旦发货,请进入 经销商终端平台 维护相应的供应商发货时间<br/>";
            mailContent += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            SEMailListController.Add(IHISCESvrSupperEmails, mailSubject, mailContent);
        }
        /// <summary>
        /// 品情驳回,服务担当页面
        /// </summary>
        /// <param name="QltyId"></param>
        public static void CancelQltyEmail(int QltyId)
        {
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.UserId);
            //邮件接收人为，经销商及相应服务担当
            string mailEmail = svrObj.EMail;
            mailEmail += ";" + OUserController.GetById(obj.SrvActUserId).EMail;          
            string mailSubject = string.Format("您的品情{0}已被驳回", obj.ClaimsNumber);
            string mailContent = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            mailContent += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);

            mailContent += string.Format("驳回原因:<br/><b>{0}</b><br/>", obj.RejectReason);
            mailContent += string.Format("<b>您可以进入信息平台对品情{0}修改再提交审核。</b><br/>", obj.ClaimsNumber);
            //mailContent += string.Format("需求配件明细:<br/><b>{0}</b><br/>", obj.FaultDescription);
            //List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId);
            //foreach (AgentQltyPartsInfo itm in listParts)
            //{
            //    mailContent += "<table>";
            //    mailContent += "<tr><td>配件号<td><td>配件名称<td><td>数量<td><td></td>";

            //    mailContent += "</table>";
            //}

            mailContent += "<br/>==============================================================================<br/>";
            mailContent += "<br/>请进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 查看 进行查看.<br/>";
            mailContent += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);
        }

        /// <summary>
        /// 拒赔品情
        /// </summary>
        /// <param name="QltyId"></param>
        public static void ExclusionsQltyEmail(int QltyId)
        {
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.UserId);
            //邮件接收人为，经销商
            string mailEmail = svrObj.EMail;
            //mailEmail += ";" + OUserController.GetById(obj.SrvActUserId).EMail;
            string mailSubject = string.Format("您的品情{0}已被拒赔", obj.ClaimsNumber);
            string mailContent = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            mailContent += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            //mailContent += string.Format("需求配件明细:<br/><b>{0}</b><br/>", obj.FaultDescription);
            //List<AgentQltyPartsInfo> listParts = AgentQltyController.GetAllPartsByQltyId(QltyId);
            //foreach (AgentQltyPartsInfo itm in listParts)
            //{
            //    mailContent += "<table>";
            //    mailContent += "<tr><td>配件号<td><td>配件名称<td><td>数量<td><td></td>";

            //    mailContent += "</table>";
            //}

            mailContent += "<br/>==============================================================================<br/>";
            mailContent += "<br/>请进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 查看 进行查看.<br/>";
            mailContent += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);
        }

        /// <summary>
        /// 驳回品情，审核页面
        /// </summary>
        /// <param name="QltyId"></param>
        public static void NoPassEmail(int QltyId)
        {
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.SrvActUserId);
            //获取所有需要接收品情驳回的人员,服务担当,服务经理
            string EMail = OUserController.GetById(obj.SrvActUserId).EMail;//服务担当EMAIL
            int userId = obj.SrvActUserId;
            while (true)
            {
                AgentPowerConfigInfo power = AgentConfigController.GetByUserId(userId);               
                if (power.ParId == 0)
                    break;
                AgentPowerConfigInfo SvrManagerPower = AgentConfigController.GetById(power.ParId);
                 userId = SvrManagerPower.UserId;
                 if (obj.SrvMangerUserId == userId)
                     break;
                
               
                EMail = EMail + ";" + OUserController.GetById(SvrManagerPower.UserId).EMail;
            }
            //
            OUserInfo AgentObj = OUserController.GetById(obj.UserId);
            EMail = EMail + ";" + AgentObj.EMail;



            string mailSubject = string.Format("您的品情{0}已被{1}驳回", obj.ClaimsNumber, OUserController.GetById(obj.SrvActUserId).RealName);
            string mailContent = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            mailContent += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            mailContent += string.Format("驳回原因:<br/><b>{0}</b><br/>", obj.RejectReason);
            mailContent += "<br/>==============================================================================<br/>";
            mailContent += "<br/>请进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 查看 进行查看.<br/>";
            mailContent += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            SEMailListController.Add(EMail, mailSubject, mailContent);
        }
        /// <summary>
        /// 确认品情后,通知经销商
        /// </summary>
        /// <param name="QltyId"></param>
        public static void EndEmail(int QltyId)
        {
            AgentQltyInfo obj = AgentQltyController.GetByQltyId(QltyId);
            OUserInfo svrObj = OUserController.GetById(obj.UserId);

            string mailSubject = string.Format("您的品情{0}机号{1}服务担当已确认", obj.ClaimsNumber,obj.SerialNumber);
            string mailContent = string.Format("品情号:<b>{0}</b><br/>", obj.ClaimsNumber);
            mailContent += string.Format("机号:<b>{0}</b><br/>", obj.SerialNumber);
            mailContent += string.Format("我司 服务担当{0} 已处理完此品情,同时也通知配件部发货(如有需求)<br/>", obj.SrvActRealName);
            mailContent += "可进入 <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 进入查看.<br/>";
            mailContent += "==============================================================================<br/>";
            mailContent += "注意:<BR/>1.如果有配件需求,在收到配件后,务必进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 进入查看 填写相应的配件收货时间(同一单品情以最后一次收到配件为准)<br/>";
            mailContent += "2.如故障已排除,也务必进入  <a href='http://sys.ihisce.com:91' target='new'>IHISCE经销商终端平台</a> 进入查看 填写相应的故障排除时间<br/>";
            mailContent += "<BR/><BR/>以上内容为 IHISCE 信息平台系统自动发送，请勿回复.";
            SEMailListController.Add(svrObj.EMail, mailSubject, mailContent);
        }
*/
    }
}
